<template>
  <div class="container">
    <el-row :gutter="24">
       <el-col :span="12">
        <el-card shadow="hover">
          <div slot="header" class="clearfix">
            <span>文件存储设置</span>
            <el-button
              style="float: right; padding: 3px 0"
              type="text"
              @click="storageread=!storageread"
            >编辑</el-button>
          </div>
          <el-form
            ref="form"
            :model="aliobs"
            label-width="120px"
            size="mini"
            :disabled="storageread"
          >
            <el-form-item label="本地存储路径:">
              <el-input v-model="storage.value1"></el-input>
            </el-form-item>
            <el-form-item label="本地站点前缀:">
              <el-input v-model="storage.value2"></el-input>
            </el-form-item>
            <el-form-item label="阿里云OBS前缀:">
              <el-input v-model="storage.value3"></el-input>
            </el-form-item>
             <el-form-item label="存储方式:">
              <el-switch
                v-model="storage.value"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-value="obs"
                inactive-value="local"
                active-text="obs存储"
                inactive-text="本地存储"
              ></el-switch>
            </el-form-item>
            <el-form-item size="mini" :hidden="storageread">
              <el-button type="primary" @click="saveSystemParam('storage')">保存</el-button>
              <el-button @click="storageread=true">取消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover">
          <div slot="header" class="clearfix">
            <span>阿里云存储</span>
            <el-button
              style="float: right; padding: 3px 0"
              type="text"
              @click="aliobsread=!aliobsread"
            >编辑</el-button>
          </div>
          <el-form
            ref="form"
            :model="aliobs"
            label-width="120px"
            size="mini"
            :disabled="aliobsread"
          >
            <el-form-item label="endpoint:">
              <el-input v-model="aliobs.value1"></el-input>
            </el-form-item>
            <el-form-item label="accessKeyId:">
              <el-input v-model="aliobs.value2"></el-input>
            </el-form-item>
            <el-form-item label="accessKeySecret:">
              <el-input v-model="aliobs.value3"></el-input>
            </el-form-item>
            <el-form-item label="bucketName:">
              <el-input v-model="aliobs.value4"></el-input>
            </el-form-item>
            <el-form-item size="mini" :hidden="aliobsread">
              <el-button type="primary" @click="saveSystemParam('aliobs')">保存</el-button>
              <el-button @click="aliobsread=true">取消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="12">
        <el-card shadow="hover">
          <div slot="header" class="clearfix">
            <span>小程序配置</span>
            <el-button style="float: right; padding: 3px 0" type="text" @click="xcxread=!xcxread">编辑</el-button>
          </div>
          <el-form ref="form" :model="xcx" label-width="120px" size="mini" :disabled="xcxread">
            <el-form-item label="名称:">
              <el-input v-model="xcx.name"></el-input>
            </el-form-item>
            <el-form-item label="appID:">
              <el-input v-model="xcx.app_id"></el-input>
            </el-form-item>
            <el-form-item label="appSecret:">
              <el-input v-model="xcx.app_secret"></el-input>
            </el-form-item>
            <el-form-item label="商户号:">
              <el-input v-model="xcx.pay_mch_id"></el-input>
            </el-form-item>
            <el-form-item label="secretKey:">
              <el-input v-model="xcx.pay_secret_key"></el-input>
            </el-form-item>
            <el-form-item size="mini" :hidden="xcxread">
              <el-button type="primary" @click="saveXcx">保存</el-button>
              <el-button @click="xcxread=true">取消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "dashboard",
  data() {
    return {
      user: {},
      xcxread: true,
      aliobsread: true,
      storageread: true,
      xcx: {},
      aliobs: {},
      storage:{}
    };
  },
  methods: {
    getData() {
      this.$axios.get(this.HOST + "/xiaochengxu/get").then(res => {
        this.xcx = res.data.data;
      });
      this.$axios
        .get(this.HOST + "/system/getByName", { params: { name: "aliobs" } })
        .then(res => {
          this.aliobs = res.data.data;
        });
         this.$axios
        .get(this.HOST + "/system/getByName", { params: { name: "storage" } })
        .then(res => {
          this.storage = res.data.data;
        });
    },
    saveXcx() {
      this.$axios({
        method: "post",
        url: this.HOST + "/xiaochengxu/modify",
        headers: {
          "Content-type": "application/x-www-form-urlencoded"
        },
        data: this.xcx
      }).then(res => {
        if (res.data.code == 0) {
          this.$message.success("保存成功");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    saveSystemParam(name) {
      this.$axios({
        method: "post",
        url: this.HOST + "/system/modify",
        headers: {
          "Content-type": "application/x-www-form-urlencoded"
        },
        data: this[name]
      }).then(res => {
        if (res.data.code == 0) {
          this.$message.success("保存成功");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    }
  },
  computed: {},
  created: function() {
    this.getData();
  }
};
</script>


<style scoped>
.container {
  background-color: #fff;
}
.el-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}
</style>
